qui(function (require, exports, module) {
    SysConfig.Util = $.extend(true, {}, EpgWeb.Util, {
        formatter: {
            operator_config:function (cellvalue, options, rowObject){
                return '<a href="javascript:;" onclick="SysConfig.Util.openEditView(' + rowObject.id + ' )">修改</a>' ;
            },
            status:function (cellvalue, options, rowObject){
                if(cellvalue == 2){
                    return "启用"
                }else if(cellvalue ==1){
                    return "未启用"
                }else{
                    return "undefined:"+cellvalue
                }
            }
        },
        openEditView:function(elementId){
            $("#edit-dlg").dialog("open");
            var parentDiv = $("#addFrom");
            parentDiv[0].reset();
            parentDiv.find("input[name=id]").val(elementId);
            var entity = SysConfig.Config.PageBean.findData("id",elementId);
            parentDiv.find("input[name=type]").val(entity.type);
            parentDiv.find("input[name=type]").attr("disabled","disabled");
            parentDiv.find("input[name=key]").val(entity.key);

            parentDiv.find("input[name=val]").val(entity.val);
            parentDiv.find("input[name=desc]").val(entity.desc);
            parentDiv.find("input[name=status][value='"+entity.status+"']").prop("checked", true);
        },
        openAddView:function(){
            $("#edit-dlg").dialog("open");
            var parentDiv = $("#addFrom");
            parentDiv[0].reset();
            parentDiv.find("input[name=id]").val("-1");
            parentDiv.find("input[name=type]").removeAttr("disabled");
            parentDiv.find("input[name=key]").removeAttr("disabled");

        },
        doCancel:function(){
            $("#edit-dlg").dialog("close");
        },

        checkParams: function(params) {
            if(params['type'] == '') {
                EpgWeb.Plugin.showTips({type:"error",content:"请填写类型" })
                return false;
            }

            if(params['key'] == '' || isNaN(params['key'])) {
                EpgWeb.Plugin.showTips({type:"error",content:"请填写索引" })
                return false;
            }

            if(params['val'] == '') {
                EpgWeb.Plugin.showTips({type:"error",content:"请填写值" })
                return false;
            }

            if(params['desc'] == '') {
                EpgWeb.Plugin.showTips({type:"error",content:"请填写描述" })
                return false;
            }
            return true;
        },

        doSubmitElement:function(){
            var self= this;
            var params = getParam($("#addFrom"));

            if(!self.checkParams(params)) {
                return;
            }

            if(params.id < 0) {
                self.submitAdd(JSON.stringify(params));
            }else{
                self.submitEdit(JSON.stringify(params));
            }
        },
        submitEdit:function(element){
            SysConfig.Dao.submitEdit({data:element},function(data){
                if(data != null && data.code =="A00000" ){
                    $('#edit-dlg').dialog('close');
                    EpgWeb.Plugin.showTips({type:"success",content:data.msg })
                    location.reload();
                }else{
                    EpgWeb.Plugin.showTips({type:"error",content:data.msg })
                }
            })
        },
        submitAdd:function(element){
            SysConfig.Dao.submitAdd({data:element},function(data){
                if(data != null && data.code =="A00000" ){
                    $('#edit-dlg').dialog('close');
                    EpgWeb.Plugin.showTips({type:"success",content:data.msg })
                    location.reload();
                }else{
                    EpgWeb.Plugin.showTips({type:"error",content:data.msg })
                }
            })
        },
        PageBean: null

    });


});